import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QCheckBox, QTimeEdit
from PyQt5.QtCore import Qt


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        # 加载Qt Designer生成的UI文件
        # 例如，如果你的UI文件名为 "mainwindow.ui"
        # from PyQt5.uic import loadUi
        # loadUi('mainwindow.ui', self)

        # 假设这里已经通过Qt Designer加载了UI文件，并且checkBox和timeEdit是其中的控件
        self.autoRefreshCheckBox = self.findChild(QCheckBox, 'autoRefreshCheckBox')
        self.timeEdit = self.findChild(QTimeEdit, 'timeEdit')

        # 设置初始状态
        self.timeEdit.setVisible(False)
        self.timeEdit.setReadOnly(True)

        # 连接信号与槽
        self.autoRefreshCheckBox.stateChanged.connect(self.on_auto_refresh_changed)

    def on_auto_refresh_changed(self, state):
        """ 根据QCheckBox的状态来设置QTimeEdit的可见性和只读状态 """
        if state == Qt.Checked:
            self.timeEdit.setVisible(True)
            self.timeEdit.setReadOnly(False)
        else:
            self.timeEdit.setVisible(False)
            self.timeEdit.setReadOnly(True)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())
